/**
 * Created by Administrator on 2017/11/11.
 */

//加载页面时下载大盘K线图
function getBaseImageK(){
    if($("#code").val() ==""){
        var data="sh000001";
    }
    $.ajax({
        url:"./stock/info/"+data,
        type:"GET",
        data:data,
        // processData:false,
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        dataType:"json",
        success:function(result){
            //var obj=eval("("+result+")");
            //或者$.parsejson(data);
            if(result.code==0){
                location.href="./index.html";
                alert(result.message);
            }else if(result.code==1){
                alert(result.message);
            }
        }
    });
}


//根据股票Id查询K线图
 function getStockKimageById(){
    if($("#code").val() ==""){
        alert("股票代码不能为空！");
        $("#code").focus();
        return;
    }
    var data=$("#code").val();
    console.log(data);
    $.ajax({
        url:"./stock/info/"+data,
        type:"GET",
       // data:data,
        // processData:false,
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        dataType:"json",
        success:function(result){
              console.log(result);
            //var obj=eval("("+result+")");
            //或者$.parsejson(sdata);

             //   var obj=eval("("+result.object+")");
              //  var obj=JSON.parse(result);
                console.log(result.stockName);
                $("#stockName").val(result.stockName);
                $("#stockCode").val(result.stockCode);
                $("#todayOpenPrice").val(result.todayOpenPrice);
                $("#todayClosePrice").val(result.todayClosePrice);
                $("#currentPrice").val(result.currentPrice);
                $("#todayHighestPrice").val(result.todayHighestPrice);
                $("#todayLowestPrice").val(result.todayLowestPrice);
                $("#bidPrice").val(result.bidPrice);
                $("#sellPrice").val(result.sellPrice);
                $("#tradedStockesNum").val(result.tradedStockesNum);
                $("#tradedStocksAmount").val(result.tradedStocksAmount);
                $("#buyFirstPrice").val(result.buyFirstPrice);
                $("#buySecondPrice").val(result.buySecondPrice);
                $("#buyThirdPrice").val(result.buyThirdPrice);
                $("#buyFourthPrice").val(result.buyFourthPrice);
                $("#buyFifthPrice").val(result.buyFifthPrice);
                $("#sellFirstPrice").val(result.sellFirstPrice);
                $("#sellSecondPrice").val(result.sellSecondPrice);
                $("#sellThirdPrice").val(result.sellThirdPrice);
                $("#sellFourthPrice").val(result.sellFourthPrice);
                $("#sellFifthPrice").val(result.sellFifthPrice);
                $("#currentDate").val(result.currentDate);
                $("#currentTime").val(result.currentTime);

        }
    });
 }
//点击不同的button切换不同的背景图
function  changeImageByClick(){
     $("button").click(function(){
        var val=this.value;
        console.log(val);
        if(val=="btn_day"){
            $("#c_center_up_image").css("background-image","url(image/daily.gif)");
        }else if(val=="btn_week"){
            $("#c_center_up_image").css("background-image","url(image/weekly.gif)");
        }else if(val=="btn_month"){
            $("#c_center_up_image").css("background-image","url(image/monthly.gif)");
        }else if(val=="btn_min"){
            $("#c_center_up_image").css("background-image","url(image/min.gif)");
        }
    });
}

//获得所有股票信息
function getAllStockinfo(){
    var tbody=window.document.getElementById("shuju");
    $.ajax({
        url:" ./stock/all",
        type:"GET",
        dataType:"json",
        success:function(data){
            console.log(data);
         if(data.code==0){
           var str="";
           var tdata=data.object;
           for( i in tdata){
             str +="<tr>"+"<td>"+tdata[i].stockCode+"</td>"+"<td>"+tdata[i].stockName+"</td>"+"<td>"+tdata[i].todayOpenPrice+"</td>"
                 + "<td>"+tdata[i].todayClosePrice+"</td>"+"<td>"+tdata[i].currentPrice+"</td>"+ "<td>"+tdata[i].todayHighestPrice+"</td>"
                 +"<td>"+tdata[i].todayLowestPrice+"</td>" +"<td>"+tdata[i].bidPrice+"</td>"+"<td>"+tdata[i].sellPrice+"</td>"
                 +"<td>"+tdata[i].tradedStockesNum+"</td>"+"<td>"+tdata[i].tradedStocksAmount+"</td>"+ "<td>"+tdata[i].currentDate+"</td>"
                 +"<td>"+tdata[i].currentTime+"</td>"+"</tr>";
                    tbody.innerHTML =str;
           }
         }
        },
        error:function(){
            alert("查询失败！");
        }
    });
}




